package com.huluobo.a2307douyindemo.utils

import android.util.TypedValue
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ApiUtils
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.SPUtils
import com.huluobo.a2307douyindemo.App
import com.huluobo.a2307douyindemo.MainActivity

/**
 *  Created by LC on 2025/9/27.
 *  像素转换dp工具类
 */
object DensityUtils {
    //dp转px
    fun dp2px(dpVal: Float): Int {
        return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            dpVal, App.instance.resources.displayMetrics
        ).toInt()
    }

    //px转dp
    fun px2dp(pxVal: Float): Float {
        val scale: Float = App.instance.resources.displayMetrics.density
        return pxVal / scale
    }

    //sp转px
    fun sp2px(spVal: Float): Int {
        return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_SP,
            spVal, App.instance.resources.displayMetrics
        ).toInt()
    }

    //px转sp
    fun px2sp(pxVal: Float): Float {
        val scale: Float = App.instance.resources.displayMetrics.scaledDensity
        return pxVal / scale
    }
}